package com.yunxiangyue

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter

class looperPageAdapter: PagerAdapter() {


    private var mpics= mutableListOf<Int>()
    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        var realPosition=position%mpics.size
        var imageView= ImageView(container.context)
        imageView.setBackgroundResource(mpics.get(realPosition))
        container.addView(imageView)
        return imageView
    }
    override fun getCount(): Int {
        if(mpics.size!=null){
            return mpics.size
        }
        return 0
    }


    public fun getMpicsSize():Int{
        if(mpics.size!=null){
            return mpics.size
        }
        return 0
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    public fun setData(arrayList:ArrayList<Int>){
        this.mpics=arrayList
    }


}